﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web.Mvc;
using System.Web.Mvc.Html;
using System.Web.Routing;

namespace mForum.Web.Common.Extensions
{
    using mForum.Core.Infrastructure.IoC;
    using mForum.Web.Common.Infrastructure;
    using mForum.Web.Common.Infrastructure.AssetManager;

    public static class AssetManagerExtensions
    {
        public static void RegisterScript(this HtmlHelper instance, string scriptUrl, AssetCategory assetCategory)
        {
            IoC.GetInstance<IAssetManager>().RegisterAsset(scriptUrl, AssetType.Script, assetCategory);
        }

        public static void RegisterCss(this HtmlHelper instance, string cssUrl, AssetCategory assetCategory)
        {
            IoC.GetInstance<IAssetManager>().RegisterAsset(cssUrl, AssetType.Stylesheet, assetCategory);
        }

        public static string GenerateAssetPlaceholders(this HtmlHelper instance)
        {
            StringBuilder assetPlaceholders = new StringBuilder();

            foreach (var type in AssetType.AssetTypeDictionary)
            {
                assetPlaceholders.AppendLine(String.Format("#{0}_REFERENCE#", type.Key.ToUpper()));
            }

            return assetPlaceholders.ToString();
        }
    }
}
